<%+cbi/valueheader%>
<script type="text/javascript">
//<![CDATA[
function padright(str, cnt, pad) {
	return str + Array(cnt + 1).join(pad);
}

function b64EncodeUnicode(str) {
	return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
		return String.fromCharCode('0x' + p1);
	}));
}

function b64encutf8safe(str) {
	return b64EncodeUnicode(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, '');
}

function b64DecodeUnicode(str) {
	return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) {
		return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
	}).join(''));
}

function b64decutf8safe(str) {
	var l;
	str = str.replace(/-/g, "+").replace(/_/g, "/");
	l = str.length;
	l = (4 - l % 4) % 4;
	if (l) str = padright(str, l, "=");
	return b64DecodeUnicode(str);
}

function b64encsafe(str) {
	return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, '')
}

function b64decsafe(str) {
	var l;
	str = str.replace(/-/g, "+").replace(/_/g, "/");
	l = str.length;
	l = (4 - l % 4) % 4;
	if (l) str = padright(str, l, "=");
	return atob(str);
}

function dictvalue(d, key) {
	var v = d[key];
	if (typeof (v) == 'undefined' || v == '') return '';
	return b64decsafe(v);
}

function export_ssr_url(btn, urlname, sid) {
	var s = document.getElementById(urlname + '-status');
	if (!s) return false;
	var v_server = document.getElementsByName('cbid.bypass.' + sid + '.server')[0];
	var v_port = document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0];
	var v_protocol = document.getElementsByName('cbid.bypass.' + sid + '.protocol')[0];
	var v_method = document.getElementsByName('cbid.bypass.' + sid + '.encrypt_method')[0];
	var v_obfs = document.getElementsByName('cbid.bypass.' + sid + '.obfs')[0];
	var v_password = document.getElementsByName('cbid.bypass.' + sid + '.password')[0];
	var v_obfs_param = document.getElementsByName('cbid.bypass.' + sid + '.obfs_param')[0];
	var v_protocol_param = document.getElementsByName('cbid.bypass.' + sid + '.protocol_param')[0];
	var v_alias = document.getElementsByName('cbid.bypass.' + sid + '.alias')[0];
	var ssr_str = v_server.value + ":" + v_port.value + ":" + v_protocol.value + ":" + v_method.value + ":" + v_obfs.value + ":" + b64encsafe(v_password.value) + "/?obfsparam=" + b64encsafe(v_obfs_param.value) + "&protoparam=" + b64encsafe(v_protocol_param.value) + "&remarks=" + b64encutf8safe(v_alias.value);
	var textarea = document.createElement("textarea");
	textarea.textContent = "ssr://" + b64encsafe(ssr_str);
	textarea.style.position = "fixed";
	document.body.appendChild(textarea);
	textarea.select();
	try {
		document.execCommand("copy"); // Security exception may be thrown by some browsers.
		s.innerHTML = "<font style=\'color:green\'><%:Copy SSR to clipboard successfully.%></font>";
	} catch (ex) {
		s.innerHTML = "<font style=\'color:red\'><%:Unable to copy SSR to clipboard.%></font>";
	} finally {
		document.body.removeChild(textarea);
	}
	return false;
}

function import_ssr_url(btn, urlname, sid) {
		var s = document.getElementById(urlname + '-status');
		if (!s) return false;
		var ssrurl = prompt("<%:Paste sharing link here%>", "");
		if (ssrurl == null || ssrurl == "") {
			s.innerHTML = "<font style=\'color:red\'><%:User cancelled.%></font>";
			return false;
		}
		s.innerHTML = "";
		//var ssu = ssrurl.match(/ssr:\/\/([A-Za-z0-9_-]+)/i);
		var ssu = ssrurl.split('://');
		//console.log(ssu.length);
		var event = document.createEvent("HTMLEvents");
		event.initEvent("change", true, true);
		switch (ssu[0]) {
		case "hysteria":
			try {
				var url = new URL("http://" + ssu[1]);
				var params = url.searchParams;
			} catch(e) {
				alert(e);
				return false;
			}

			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].value = ssu[0];
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].dispatchEvent(event);
			document.getElementsByName('cbid.bypass.' + sid + '.server')[0].value = url.hostname;
			document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0].value = url.port || "80";
			document.getElementsByName('cbid.bypass.' + sid + '.hysteria_protocol')[0].value = params.get("protocol") || "udp";
			document.getElementsByName('cbid.bypass.' + sid + '.auth_type')[0].value = params.get("auth") ? "2" : "0";
			document.getElementsByName('cbid.bypass.' + sid + '.auth_type')[0].dispatchEvent(event);
			document.getElementsByName('cbid.bypass.' + sid + '.auth_payload')[0].value = params.get("auth") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.uplink_capacity')[0].value = params.get("upmbps") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.downlink_capacity')[0].value = params.get("downmbps") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.seed')[0].value = params.get("obfsParam") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.tls_host')[0].value = params.get("peer") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.quic_tls_alpn')[0].value = params.get("alpn") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.insecure')[0].checked = params.get("insecure") ? true : false;
			document.getElementsByName('cbid.bypass.' + sid + '.alias')[0].value = url.hash ? decodeURIComponent(url.hash.slice(1)) : "";

			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			return false;
		case "ss":
			var url0, param = "";
			var sipIndex = ssu[1].indexOf("@");
			var ploc = ssu[1].indexOf("#");
			if (ploc > 0) {
				url0 = ssu[1].substr(0, ploc);
				param = ssu[1].substr(ploc + 1);
			} else {
				url0 = ssu[1];
			}
			if (sipIndex != -1) {
				// SIP002
				var userInfo = b64decsafe(url0.substr(0, sipIndex));
				var temp = url0.substr(sipIndex + 1).split("/?");
				var serverInfo = temp[0].split(":");
				var server = serverInfo[0];
				var port = serverInfo[1].replace("/","");
				var method, password, plugin, pluginOpts;
				if (temp[1]) {
					var pluginInfo = decodeURIComponent(temp[1]);
					var pluginIndex = pluginInfo.indexOf(";");
					var pluginNameInfo = pluginInfo.substr(0, pluginIndex);
					plugin = pluginNameInfo.substr(pluginNameInfo.indexOf("=") + 1);
					pluginOpts = pluginInfo.substr(pluginIndex + 1);
				}
				var userInfoSplitIndex = userInfo.indexOf(":");
				if (userInfoSplitIndex != -1) {
					method = userInfo.substr(0, userInfoSplitIndex);
					password = userInfo.substr(userInfoSplitIndex + 1);
				}
				document.getElementsByName('cbid.bypass.' + sid + '.type')[0].value = ssu[0];
				document.getElementsByName('cbid.bypass.' + sid + '.type')[0].dispatchEvent(event);
				document.getElementsByName('cbid.bypass.' + sid + '.server')[0].value = server;
				document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0].value = port;
				document.getElementsByName('cbid.bypass.' + sid + '.password')[0].value = password || "";
				document.getElementsByName('cbid.bypass.' + sid + '.encrypt_method_ss')[0].value = method || "";
				document.getElementsByName('cbid.bypass.' + sid + '.plugin')[0].value = plugin || "none";
				document.getElementsByName('cbid.bypass.' + sid + '.plugin')[0].dispatchEvent(event);
				if (plugin != undefined) {
				document.getElementsByName('cbid.bypass.' + sid + '.plugin_opts')[0].value = pluginOpts || "";
				}
				if (param != undefined) {
					document.getElementsByName('cbid.bypass.' + sid + '.alias')[0].value = decodeURI(param);
				}
				s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			} else {
				var sstr = b64decsafe(url0);
				document.getElementsByName('cbid.bypass.' + sid + '.type')[0].value = ssu[0];
				document.getElementsByName('cbid.bypass.' + sid + '.type')[0].dispatchEvent(event);
				var team = sstr.split('@');
				var part1 = team[0].split(':');
				var part2 = team[1].split(':');
				document.getElementsByName('cbid.bypass.' + sid + '.server')[0].value = part2[0];
				document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0].value = part2[1];
				document.getElementsByName('cbid.bypass.' + sid + '.password')[0].value = part1[1];
				document.getElementsByName('cbid.bypass.' + sid + '.encrypt_method_ss')[0].value = part1[0];
				if (param != undefined) {
					document.getElementsByName('cbid.bypass.' + sid + '.alias')[0].value = decodeURI(param);
				}
				s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			}
			return false;
		case "ssr":
			var sstr = b64decsafe(ssu[1]);
			var ploc = sstr.indexOf("/?");
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].value = ssu[0];
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].dispatchEvent(event);
			var url0, param = "";
			if (ploc > 0) {
				url0 = sstr.substr(0, ploc);
				param = sstr.substr(ploc + 2);
			}
			var ssm = url0.match(/^(.+):([^:]+):([^:]*):([^:]+):([^:]*):([^:]+)/);
			if (!ssm || ssm.length < 7) return false;
			var pdict = {};
			if (param.length > 2) {
				var a = param.split('&');
				for (var i = 0; i < a.length; i++) {
					var b = a[i].split('=');
					pdict[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
				}
			}
			document.getElementsByName('cbid.bypass.' + sid + '.server')[0].value = ssm[1];
			document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0].value = ssm[2];
			document.getElementsByName('cbid.bypass.' + sid + '.protocol')[0].value = ssm[3];
			document.getElementsByName('cbid.bypass.' + sid + '.encrypt_method')[0].value = ssm[4];
			document.getElementsByName('cbid.bypass.' + sid + '.obfs')[0].value = ssm[5];
			document.getElementsByName('cbid.bypass.' + sid + '.password')[0].value = b64decsafe(ssm[6]);
			document.getElementsByName('cbid.bypass.' + sid + '.obfs_param')[0].value = dictvalue(pdict, 'obfsparam');
			document.getElementsByName('cbid.bypass.' + sid + '.protocol_param')[0].value = dictvalue(pdict, 'protoparam');
			var rem = pdict['remarks'];
			if (typeof (rem) != 'undefined' && rem != '' && rem.length > 0) document.getElementsByName('cbid.bypass.' + sid + '.alias')[0].value = b64decutf8safe(rem);
			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			return false;
		case "trojan":
			try {
				var url = new URL("http://" + ssu[1]);
				var params = url.searchParams;
			} catch(e) {
				alert(e);
				return false;
			}

			document.getElementsByName('cbid.bypass.' + sid + '.alias')[0].value = url.hash ? decodeURIComponent(url.hash.slice(1)) : "";
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].value = "v2ray";
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].dispatchEvent(event);
			document.getElementsByName('cbid.bypass.' + sid + '.v2ray_protocol')[0].value = "trojan";
			document.getElementsByName('cbid.bypass.' + sid + '.v2ray_protocol')[0].dispatchEvent(event);
			document.getElementsByName('cbid.bypass.' + sid + '.server')[0].value = url.hostname;
			document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0].value = url.port || "80";
			document.getElementsByName('cbid.bypass.' + sid + '.password')[0].value = decodeURIComponent(url.username);
			document.getElementsByName('cbid.bypass.' + sid + '.tls')[0].checked = true;
			document.getElementsByName('cbid.bypass.' + sid + '.tls')[0].dispatchEvent(event);
			document.getElementsByName('cbid.bypass.' + sid + '.fingerprint')[0].value = params.get("fp") || "";
			document.getElementsByName('cbid.bypass.' + sid + '.tls_host')[0].value = params.get("sni");
			if (params.get("allowInsecure") === "1") {
				document.getElementsByName('cbid.bypass.' + sid + '.insecure')[0].checked = true; // 设置 insecure 为 true
				document.getElementsByName('cbid.bypass.' + sid + '.insecure')[0].dispatchEvent(event); // 触发事件
			}
			document.getElementsByName('cbid.bypass.' + sid + '.transport')[0].value = 
				params.get("type") == "http" ? "h2" : 
				(["tcp", "raw"].includes(params.get("type")) ? "raw" : 
				(params.get("type") || "raw"));
			document.getElementsByName('cbid.bypass.' + sid + '.transport')[0].dispatchEvent(event);
			switch (params.get("type")) {
			case "ws":
				if (params.get("security") !== "tls") {
					setElementValue('cbid.bypass.' + sid + '.ws_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
				}
				setElementValue('cbid.bypass.' + sid + '.ws_path', params.get("path") ? decodeURIComponent(params.get("path")) : "/");
				break;
			case "httpupgrade":
				if (params.get("security") !== "tls") {
					document.getElementsByName('cbid.bypass.' + sid + '.httpupgrade_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : "";
				}
				document.getElementsByName('cbid.bypass.' + sid + '.httpupgrade_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "/";
				break;
			case "splithttp":
				if (params.get("security") !== "tls") {
					document.getElementsByName('cbid.bypass.' + sid + '.splithttp_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : "";
				}
				document.getElementsByName('cbid.bypass.' + sid + '.splithttp_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "/";
				break;
			case "xhttp":
				if (params.get("security") !== "tls") {
					document.getElementsByName('cbid.bypass.' + sid + '.xhttp_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : "";
				}
				document.getElementsByName('cbid.bypass.' + sid + '.xhttp_mode')[0].value = params.get("mode") || "auto";
				document.getElementsByName('cbid.bypass.' + sid + '.xhttp_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "/";
				if (params.get("extra") && params.get("extra").trim() !== "") {
					document.getElementsByName('cbid.bypass.' + sid + '.enable_xhttp_extra')[0].checked = true; // 设置 enable_xhttp_extra 为 true
					document.getElementsByName('cbid.bypass.' + sid + '.enable_xhttp_extra')[0].dispatchEvent(event); // 触发事件
					document.getElementsByName('cbid.bypass.' + sid + '.xhttp_extra')[0].value = params.get("extra") || "";
				}
				break;
			case "kcp":
				document.getElementsByName('cbid.bypass.' + sid + '.kcp_guise')[0].value = params.get("headerType") || "none";
				document.getElementsByName('cbid.bypass.' + sid + '.seed')[0].value = params.get("seed") || "";
				break;
			case "http":
			/* this is non-standard, bullshit */
			case "h2":
				document.getElementsByName('cbid.bypass.' + sid + '.h2_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : "";
				document.getElementsByName('cbid.bypass.' + sid + '.h2_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "";
				break;
			case "quic":
				document.getElementsByName('cbid.bypass.' + sid + '.quic_guise')[0].value = params.get("headerType") || "none";
				document.getElementsByName('cbid.bypass.' + sid + '.quic_security')[0].value = params.get("quicSecurity") || "none";
				document.getElementsByName('cbid.bypass.' + sid + '.quic_key')[0].value = params.get("key") || "";
				break;
			case "grpc":
				document.getElementsByName('cbid.bypass.' + sid + '.serviceName')[0].value = params.get("serviceName") || "";
				document.getElementsByName('cbid.bypass.' + sid + '.grpc_mode')[0].value = params.get("mode") || "gun";
				break;
			case "raw":
			case "tcp":
				document.getElementsByName('cbid.bypass.' + sid + '.tcp_guise')[0].value = params.get("headerType") || "none";
				document.getElementsByName('cbid.bypass.' + sid + '.tcp_guise')[0].dispatchEvent(event);
				if (params.get("headerType") === "http") {
					document.getElementsByName('cbid.bypass.' + sid + '.http_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : "";
					document.getElementsByName('cbid.bypass.' + sid + '.http_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "";
				}
				break;
			}

			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			return false;
		case "vmess":
			var sstr = b64DecodeUnicode(ssu[1]);
			var ploc = sstr.indexOf("/?");
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].value = "v2ray";
			document.getElementsByName('cbid.bypass.' + sid + '.type')[0].dispatchEvent(event);
			document.getElementsByName('cbid.bypass.' + sid + '.v2ray_protocol')[0].value = "vmess";
			document.getElementsByName('cbid.bypass.' + sid + '.v2ray_protocol')[0].dispatchEvent(event);
			var url0, param = "";
			if (ploc > 0) {
				url0 = sstr.substr(0, ploc);
				param = sstr.substr(ploc + 2);
			}
			var ssm = JSON.parse(sstr);
			document.getElementsByName('cbid.bypass.' + sid + '.alias')[0].value = ssm.ps;
			document.getElementsByName('cbid.bypass.' + sid + '.server')[0].value = ssm.add;
			document.getElementsByName('cbid.bypass.' + sid + '.server_port')[0].value = ssm.port;
			document.getElementsByName('cbid.bypass.' + sid + '.alter_id')[0].value = ssm.aid;
			document.getElementsByName('cbid.bypass.' + sid + '.vmess_id')[0].value = ssm.id;
			document.getElementsByName('cbid.bypass.' + sid + '.transport')[0].value = 
				(ssm.net === "raw" || ssm.net === "tcp") ? "raw" : ssm.net;
			document.getElementsByName('cbid.bypass.' + sid + '.transport')[0].dispatchEvent(event);
			if (ssm.net === "raw" || ssm.net === "tcp") {
				if (ssm.type && ssm.type != "http") {
					ssm.type = "none";
				} else {
					document.getElementsByName('cbid.bypass.' + sid + '.http_host')[0].value = ssm.host;
					document.getElementsByName('cbid.bypass.' + sid + '.http_path')[0].value = ssm.path;
				}
				document.getElementsByName('cbid.bypass.' + sid + '.tcp_guise')[0].value = ssm.type;
				document.getElementsByName('cbid.bypass.' + sid + '.tcp_guise')[0].dispatchEvent(event);
			}
			if (ssm.net == "ws") {
				document.getElementsByName('cbid.bypass.' + sid + '.ws_host')[0].value = ssm.host;
				document.getElementsByName('cbid.bypass.' + sid + '.ws_path')[0].value = ssm.path;
			}
			if (ssm.net == "httpupgrade") {
				document.getElementsByName('cbid.bypass.' + sid + '.httpupgrade_host')[0].value = ssm.host;
				document.getElementsByName('cbid.bypass.' + sid + '.httpupgrade_path')[0].value = ssm.path;
			}
			if (ssm.net == "splithttp") {
				document.getElementsByName('cbid.bypass.' + sid + '.splithttp_host')[0].value = ssm.host;
				document.getElementsByName('cbid.bypass.' + sid + '.splithttp_path')[0].value = ssm.path;
			}
			if (ssm.net == "xhttp") {
				document.getElementsByName('cbid.bypass.' + sid + '.xhttp_mode')[0].value = ssm.mode;
				document.getElementsByName('cbid.bypass.' + sid + '.xhttp_host')[0].value = ssm.host;
				document.getElementsByName('cbid.bypass.' + sid + '.xhttp_path')[0].value = ssm.path;
				if (params.get("extra") && params.get("extra").trim() !== "") {
					document.getElementsByName('cbid.bypass.' + sid + '.enable_xhttp_extra')[0].checked = true; // 设置 enable_xhttp_extra 为 true
					document.getElementsByName('cbid.bypass.' + sid + '.enable_xhttp_extra')[0].dispatchEvent(event); // 触发事件
					document.getElementsByName('cbid.bypass.' + sid + '.xhttp_extra')[0].value = ssm.extra;
				}
			}
			if (ssm.net == "h2") {
				document.getElementsByName('cbid.bypass.' + sid + '.h2_host')[0].value = ssm.host;
				document.getElementsByName('cbid.bypass.' + sid + '.h2_path')[0].value = ssm.path;
			}
			if (ssm.net == "quic") {
				document.getElementsByName('cbid.bypass.' + sid + '.quic_security')[0].value = ssm.securty;
				document.getElementsByName('cbid.bypass.' + sid + '.quic_key')[0].value = ssm.key;
			}
			if (ssm.net == "kcp") {
				document.getElementsByName('cbid.bypass.' + sid + '.kcp_guise')[0].value = ssm.type;
			}
			if (ssm.tls == "tls") {
				document.getElementsByName('cbid.bypass.' + sid + '.tls')[0].checked = true;
				document.getElementsByName('cbid.bypass.' + sid + '.tls')[0].dispatchEvent(event);
				document.getElementsByName('cbid.bypass.' + sid + '.fingerprint')[0].value = ssm.fp;
				if (ssm.net == "xhttp") {
					document.getElementsByName('cbid.bypass.' + sid + '.xhttp_alpn')[0].value = ssm.alpn;
				}
				document.getElementsByName('cbid.bypass.' + sid + '.tls_host')[0].value = ssm.sni || ssm.host;
			}
			if (ssm.mux !== undefined) {
				document.getElementsByName('cbid.bypass.' + sid + '.mux')[0].checked = true;
				document.getElementsByName('cbid.bypass.' + sid + '.mux')[0].dispatchEvent(event);
			}
			if (ssm.xmux !== undefined) {
				document.getElementsByName('cbid.bypass.' + sid + '.xmux')[0].checked = true;
				document.getElementsByName('cbid.bypass.' + sid + '.xmux')[0].dispatchEvent(event);
			}
			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			return false;
		case "vless":
			try {
				var url = new URL("http://" + ssu[1]);
				var params = url.searchParams;
			} catch(e) {
				alert(e);
				return false;
			}
			// Check if the elements exist before trying to modify them
			function setElementValue(name, value) {
				const element = document.getElementsByName(name)[0];
				if (element) {
					if (element.type === "checkbox" || element.type === "radio") {
						element.checked = value === true;
					} else {
						element.value = value;
					}
				}
			}
			function dispatchEventIfExists(name, event) {
				const element = document.getElementsByName(name)[0];
				if (element) {
					element.dispatchEvent(event);
				}
			}
			setElementValue('cbid.bypass.' + sid + '.alias', url.hash ? decodeURIComponent(url.hash.slice(1)) : "");
			setElementValue('cbid.bypass.' + sid + '.type', "v2ray");
			dispatchEventIfExists('cbid.bypass.' + sid + '.type', event);
			setElementValue('cbid.bypass.' + sid + '.v2ray_protocol', "vless");
			dispatchEventIfExists('cbid.bypass.' + sid + '.v2ray_protocol', event);
			setElementValue('cbid.bypass.' + sid + '.server', url.hostname);
			setElementValue('cbid.bypass.' + sid + '.server_port', url.port || "80");
			setElementValue('cbid.bypass.' + sid + '.vmess_id', url.username);
			setElementValue('cbid.bypass.' + sid + '.transport', 
				params.get("type") === "http" ? "h2" : 
				(["tcp", "raw"].includes(params.get("type")) ? "raw" : 
				(params.get("type") || "tcp"))
			);
			dispatchEventIfExists('cbid.bypass.' + sid + '.transport', event);
			setElementValue('cbid.bypass.' + sid + '.vless_encryption', params.get("encryption") || "none");
			if ([ "tls", "xtls", "reality" ].includes(params.get("security"))) {
				setElementValue('cbid.bypass.' + sid + '.' + params.get("security"), true);
				dispatchEventIfExists('cbid.bypass.' + sid + '.' + params.get("security"), event);

				if (params.get("security") === "reality") {
					setElementValue('cbid.bypass.' + sid + '.reality_publickey', params.get("pbk") ? decodeURIComponent(params.get("pbk")) : "");
					setElementValue('cbid.bypass.' + sid + '.reality_shortid', params.get("sid") || "");
					setElementValue('cbid.bypass.' + sid + '.reality_spiderx', params.get("spx") ? decodeURIComponent(params.get("spx")) : "");
				}
				setElementValue('cbid.bypass.' + sid + '.tls_flow', params.get("flow") || "none");
				dispatchEventIfExists('cbid.bypass.' + sid + '.tls_flow', event);

				setElementValue('cbid.bypass.' + sid + '.xhttp_alpn', params.get("alpn") || "");
				setElementValue('cbid.bypass.' + sid + '.fingerprint', params.get("fp") || "");
				setElementValue('cbid.bypass.' + sid + '.tls_host', params.get("sni") || "");
			}
			switch (params.get("type")) {
			case "ws":
				if (params.get("security") !== "tls") {
					setElementValue('cbid.bypass.' + sid + '.ws_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
				}
				setElementValue('cbid.bypass.' + sid + '.ws_path', params.get("path") ? decodeURIComponent(params.get("path")) : "/");
				break;
			case "httpupgrade":
				if (params.get("security") !== "tls") {
					setElementValue('cbid.bypass.' + sid + '.httpupgrade_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
				}
				setElementValue('cbid.bypass.' + sid + '.httpupgrade_path', params.get("path") ? decodeURIComponent(params.get("path")) : "/");
				break;
			case "splithttp":
				if (params.get("security") !== "tls") {
					setElementValue('cbid.bypass.' + sid + '.splithttp_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
				}
				setElementValue('cbid.bypass.' + sid + '.splithttp_path', params.get("path") ? decodeURIComponent(params.get("path")) : "/");
				break;
			case "xhttp":
				if (params.get("security") !== "tls") {
					setElementValue('cbid.bypass.' + sid + '.xhttp_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
				}
				setElementValue('cbid.bypass.' + sid + '.xhttp_mode', params.get("mode") || "auto");
				setElementValue('cbid.bypass.' + sid + '.xhttp_path', params.get("path") ? decodeURIComponent(params.get("path")) : "/");
				if (params.get("extra") && params.get("extra").trim() !== "") {
					setElementValue('cbid.bypass.' + sid + '.enable_xhttp_extra', true); // 设置 enable_xhttp_extra 为 true
					dispatchEventIfExists('cbid.bypass.' + sid + '.enable_xhttp_extra', event); // 触发事件
					setElementValue('cbid.bypass.' + sid + '.xhttp_extra', params.get("extra") || "");
				}
				break;
			case "kcp":
				setElementValue('cbid.bypass.' + sid + '.kcp_guise', params.get("headerType") || "none");
				setElementValue('cbid.bypass.' + sid + '.seed', params.get("seed") || "");
				break;
			case "http":
			/* this is non-standard, bullshit */
			case "h2":
				setElementValue('cbid.bypass.' + sid + '.h2_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
				setElementValue('cbid.bypass.' + sid + '.h2_path', params.get("path") ? decodeURIComponent(params.get("path")) : "");
				break;
			case "quic":
				setElementValue('cbid.bypass.' + sid + '.quic_guise', params.get("headerType") || "none");
				setElementValue('cbid.bypass.' + sid + '.quic_security', params.get("quicSecurity") || "none");
				setElementValue('cbid.bypass.' + sid + '.quic_key', params.get("key") || "");
				break;
			case "grpc":
				setElementValue('cbid.bypass.' + sid + '.serviceName', params.get("serviceName") || "");
				setElementValue('cbid.bypass.' + sid + '.grpc_mode', params.get("mode") || "gun");
				break;
			case "tcp":
			case "raw":
				setElementValue('cbid.bypass.' + sid + '.tcp_guise', params.get("headerType") || "none");
				dispatchEventIfExists('cbid.bypass.' + sid + '.tcp_guise', event);
				if (params.get("headerType") === "http") {
					setElementValue('cbid.bypass.' + sid + '.http_host', params.get("host") ? decodeURIComponent(params.get("host")) : "");
					setElementValue('cbid.bypass.' + sid + '.http_path', params.get("path") ? decodeURIComponent(params.get("path")) : "");
				}
				break;
			}
			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
			return false;
		default:
			s.innerHTML = "<font style=\'color:red\'><%:Invalid format.%></font>";
			return false;
		}
	}
	//]]>
</script>
<input type="button" class="btn cbi-button cbi-button-apply" value="<%:Import%>" onclick="return import_ssr_url(this, '<%=self.option%>', '<%=self.value%>')" />
<span id="<%=self.option%>-status"></span>
<%+cbi/valuefooter%>
